package org.example.paymentservice.service.provider;

import lombok.RequiredArgsConstructor;
import org.example.paymentservice.entity.Order;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RequiredArgsConstructor
public class PaymentProviderFactory {
    private final Map<String, PaymentProvider> providers;

    public PaymentProvider getProvider(Order.PaymentMethod paymentMethod) {
        PaymentProvider provider = providers.get(paymentMethod.toString().toLowerCase());
        if (provider == null) {
            throw new IllegalArgumentException("Unsupported payment method: " + paymentMethod);
        }
        return provider;
    }
}